<%@ page import="java.util.List" %>
<%@ page import="com.product.pojo.Product" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }
        .container {
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #4CAF50;
        }
        table {
            width: 100%;

            margin: 0 auto;
            border-collapse: collapse;
            text-align: center;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
        }
        th {
            background-color: #4CAF50;
            color: white;
        }
        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #ddd;
        }
        td a {
            text-decoration: none;
            color: #4CAF50;
            padding: 5px 10px;
            border: 1px solid #4CAF50;
            border-radius: 5px;
            transition: background-color 0.3s;
        }
        td a:hover {
            background-color: #4CAF50;
            color: white;
        }
        .action-buttons {
            text-align: right;
            margin-top: 20px;
        }
        .action-buttons a {
            margin-left: 10px;
            color: #4CAF50;
            text-decoration: none;
            padding: 5px 10px;
            border: 1px solid #4CAF50;
            border-radius: 5px;
            transition: background-color 0.3s;
        }
        .action-buttons a:hover {
            background-color: #4CAF50;
            color: white;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>欢迎<%=session.getAttribute("username")%>~</h1>
<%
    List<Product> productList=(List<Product>)request.getAttribute("productList");
%>
<table>
    <tr>
        <th>商品id</th>
        <th>商品名字</th>
        <th>商品价格</th>
        <th>商品类型</th>
        <th>商品图片</th>
        <th>操作类型</th>
    </tr>

    <%

        for (int i = 0; i < productList.size(); i++) {
            Product products=productList.get(i);

    %>


    <tr>
        <td><%=products.getId()%></td>
        <td><%=products.getName()%></td>
        <td><%=products.getPrice()%></td>
        <td><%=products.getType()%></td>
        <td><img src="/uplocfile/<%=products.getPhoto()%>"  style="width: 100px; height: auto;"></td>
        <td>
            <a href="<%=request.getContextPath()%>/edit?name=<%=products.getName()%>">修改</a>&nbsp;&nbsp;
            <a href="<%=request.getContextPath()%>/delete?id=<%=products.getId()%>" onclick="return confirm('确定删除吗？')">删除</a>
        </td>
    </tr>
<%
    }
%>


</table>
<div class="action-buttons">
<a href="<%=request.getContextPath()%>/add.jsp" class="add-product">添加商品</a>
    <a href="<%=request.getContextPath()%>/quit">退出登录</a>
    <a href="<%=request.getContextPath()%>/modify.jsp">修改密码</a>
</div>
</div>
</body>
</html>